package com.konsung.ksdc.common.widget;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.konsung.ksdc.R;
import com.konsung.ksdc.common.utils.DensityUtils;
import com.konsung.ksdc.manager.community.AddContactActivity;
import com.konsung.ksdc.manager.community.GroupIndexActivity;
import com.konsung.ksdc.manager.machine.MipcaActivityCapture;

/**
 * 社区添加好友弹出框
 * Created by wanghantao on 2016/12/21.
 */
public class CommunityPopWindow extends PopupWindow {
    private View view;
    private LinearLayout llGroupChat;
    private LinearLayout llAddContact;
    private LinearLayout llScan;

    /**
     * 社区添加好友popupWindow
     * @param context 上下文
     * @param itemsOnClick 点击事件
     */
    public CommunityPopWindow(final Activity context, View.OnClickListener itemsOnClick) {
        super(context);

        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context
                .LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.community_popup, null);

        llGroupChat = (LinearLayout) view.findViewById(R.id.ll_group_chat);
        llAddContact = (LinearLayout) view.findViewById(R.id.ll_add_contact);
        llScan = (LinearLayout) view.findViewById(R.id.ll_scan);
      //新建群
        llGroupChat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, GroupIndexActivity.class);
                intent.putExtra("groupId", "");
                intent.putExtra("groupOwnerId", "");
                context.startActivity(intent);
                dismiss();
            }
        });
        llAddContact.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, AddContactActivity.class);
                context.startActivity(intent);
                dismiss();
            }
        });
        llScan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, MipcaActivityCapture.class);
                intent.putExtra(MipcaActivityCapture.SCAN_TYPE_CODE, MipcaActivityCapture
                        .TYPE_ADD_CONTACT);
                context.startActivity(intent);
                dismiss();
            }
        });
        //设置PopupWindow的View
        this.setContentView(view);
        //设置PopupWindow弹出窗体的宽
        this.setWidth(DensityUtils.dp2px(context, 135));
        //设置PopupWindow弹出窗体的高
        this.setHeight(DensityUtils.dp2px(context, 160));
        //设置PopupWindow弹出窗体可点击
        this.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        //this.setAnimationStyle(R.style.TakePicPopAnim);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0);
        //设置SelectPicPopupWindow弹出窗体的背景
        this.setBackgroundDrawable(dw);
    }
}
